package com.orangelife.mobile.propertyOld.adapter;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.common.jump.JumpManager;
import com.curry.android.adapter.FatherAdapter;
import com.curry.android.util.IntentHelper;
import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.constants.Constant;
import com.orangelife.mobile.propertyOld.activity.PropertyBillDetailOldActivity;

import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 物业缴费的对应单元的缴费信息
 * Created by ${shz} on 2015/12/3.
 */
public class PropertyBillListOldChildAdapter<T> extends FatherAdapter<T> {

    private Context mContext;
    private List<Map<String, Object>> list;
    private String totalCost;
    private String houseInfo;
    private String orderID;
    private boolean selected = false;
    private String mCommID;

    public PropertyBillListOldChildAdapter(Context context, List<Map<String, Object>> list, String commID) {
        this.mContext = context;
        this.list = list;
        this.mCommID = commID;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressWarnings("unchecked")
    @Override
    public BaseAdapter setList(List<T> list) {
        this.list = (List<Map<String, Object>>) list;
        return PropertyBillListOldChildAdapter.this;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_lv_property_cost_new_child, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(R.id.tvPropertyItem, viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag(R.id.tvPropertyItem);
        }
        Map<String, Object> map = list.get(position);
        totalCost = String.valueOf(map.get("totalCost"));
        houseInfo = String.valueOf(map.get("houseInfo"));
        orderID = String.valueOf(map.get("orderID"));
        viewHolder.tvPropertyItem.setText(houseInfo);
        viewHolder.tvCost.setText(Constant.RMB_FLAG + totalCost);
        viewHolder.llItem.setTag(R.id.tvCost, orderID);
        viewHolder.llItem.setOnClickListener(listener);
        return convertView;
    }

    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String orderID = String.valueOf(v.getTag(R.id.tvCost));
            jumpToBillDetail(orderID);
        }
    };

    private void jumpToBillDetail(String orderID) {
        JumpManager.jumpToOldPropertyHistoryDetail(mContext,orderID,mCommID);
    }

    static class ViewHolder {
        @Bind(R.id.ivCheck)
        ImageView ivCheck;
        @Bind(R.id.tvPropertyItem)
        TextView tvPropertyItem;
        @Bind(R.id.tvCost)
        TextView tvCost;
        @Bind(R.id.llItem)
        LinearLayout llItem;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
